﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsMobile.Status;


namespace PDAMain.Interface
{
    class NetWorkState
    {
        public static string selectedWorkOrderID = string.Empty;
        public static string dutyPerson = string.Empty;
        /// <summary>  
        /// 判断是否通过WIFI联网
        /// </summary>     
        /// <returns>true为连接上一个热点</returns>   
        public static bool checkWifiState()
        {
            
            bool ret = false;
            Microsoft.Win32.RegistryKey keyWlan = null;
            try
            {
                keyWlan = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"System\State\Hardware");
                int value = (int)keyWlan.GetValue("wifi", 0);
                if (value >= 0x00000010)
                {
                    ret = true;
                }
            }
            catch { }
            finally
            {
                if (keyWlan != null) keyWlan.Close();
            }
            ret = true;
            return ret;
        }
        /// <summary>
        /// 判断是否通过GPRS联网
        /// </summary>
        /// <returns>true为已连接</returns>
        public static bool checkGprsState()
        {
            
            GPRS isGprsOk = new GPRS();
            int Strength = SystemState.PhoneSignalStrength;//获取手机信号的强度
            if (!checkWifiState() && Strength > 0)
            {
                isGprsOk.ConnGPRS(true);
            }
            string GPRSStatus= isGprsOk.GPRS_Status();
            if (GPRSStatus == "Connected")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
